<!DOCTYPE html>
<!--
  Copyright 2011 Google Inc. All Rights Reserved.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS-IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

-->
<html><head>
<title>tv.ui.Component</title>
<script type="text/javascript" src="../testbase.js"></script>
<script type="text/javascript">
  goog.require('goog.dom');
  goog.require('goog.functions');
  goog.require('goog.testing.StrictMock');
  goog.require('tv.ui.Component');
  goog.require('tv.ui.Document');
</script>
</head>
<body>

<div id="decorateme"></div>

<script type="text/javascript">

  var component;
  var elem;
  var mockTvDocument;
  var mockMouseEvent;

  function setUp() {
    component = new tv.ui.Component();
    elem = goog.dom.getElement('decorateme');
    mockTvDocument = new goog.testing.StrictMock(tv.ui.Document);
    mockMouseEvent  = new goog.testing.StrictMock(goog.events.Event);
    document.tvUiDocument_ = mockTvDocument;
  }

  // Tests if second attempt to decorate() is successful.
  function testDoubleDecorate() {
    component.decorate(elem);
    try {
      component.decorate(elem);
      fail('Exception should be thrown.');
    } catch (e) {
      // Expected.
    }
  }

  // Checks if tv.ui.Document is being called when component is being clicked. 
  function testFocusing() {
    mockTvDocument.setFocusedComponent(component);
    mockMouseEvent.stopPropagation();
    mockTvDocument.$replay();
    mockMouseEvent.$replay();

    component.decorate(elem);
    component.onMouseDown(mockMouseEvent);

    mockTvDocument.$verify();
    mockMouseEvent.$verify();
  }

  // Case when component is disabled.
  function testFocusing_componentIsDisabled() {
    mockTvDocument.$replay();
    mockMouseEvent.$replay();

    component.isEnabled = goog.functions.FALSE;
    component.onMouseDown(mockMouseEvent);

    mockTvDocument.$verify();
    mockMouseEvent.$verify();
  }

</script>
</body></html>
